/// <reference path="Vector2.ts" />
module ew {
    export class Rectangle {
        public x: number;
        public y: number;
        public width: number;
        public height: number;

        public get left(): number {
            return this.x;
        }

        public get right(): number {
            return this.x + this.width;
        }

        public get top(): number {
            return this.y;
        }

        public get bottom(): number {
            return this.y + this.height;
        }

        public get location(): Vector2 {
            return new Vector2(this.x, this.y);
        }

        public set location(point: Vector2) {
            this.x = point.x;
            this.y = point.y;
        }

        constructor(x: number, y: number, width: number, height: number) {
            this.x = x ? x : 0;
            this.y = y ? y : 0;
            this.width = width ? width : 0;
            this.height = height ? height : 0;
        }

        public offset(point: Vector2) {
            this.x += point.x;
            this.y += point.y;
        }

        public contains(point: Vector2): bool {
            var contains = 
                point.x >= this.x &&
                this.x + this.width >= point.x &&
                point.y >= this.y &&
                this.y + this.height >= point.y;

            return contains;
        }

        public intersects(rectangle: Rectangle): bool {
             var intesects = 
                rectangle.x + rectangle.width >= this.x &&
                this.x + this.width >= rectangle.x &&
                rectangle.y + rectangle.y >= this.y &&
                this.y + this.height >= rectangle.y;

            return intesects;
        }
    }
}